<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/include.inc.jsp"%>
<!DOCTYPE html>
<html>
<head>
<%@include file="/WEB-INF/views/layout/base.ref.jsp"%>
<link rel="stylesheet" href="${ctx}/static/controls/zTree/css/zTreeStyle.css" type="text/css" />
</head>
<body>
	<form method="post" id="form1" action="${ctx}/customsearch/select">
		<input type="hidden" name="arg" id="ids" value="${vo.arg}" /> <input type="hidden" name="code" id="code"
			value="${vo.code}" /> <input type="hidden" name="pageNum" value="${vo.pageNum}" />
		<c:if test="${defaultParam != null }">
			<input type="hidden" name="defaultParam" value="${defaultParam}" />
		</c:if>
		<div class="col-xs-12">
			<div class="form-group col-xs-12"
				style="position: fixed; padding-top: 5px; padding-bottom: 5px; border-bottom: 1px solid rgb(238, 238, 238); background-color: white; z-index: 10;">
				<button class="btn btn-success" onclick="select_submit();return false;">确定</button>
				<c:forEach items="${listControl}" var="con">
					<label class="mtlabel">${con.controlName}：</label>
					<c:choose>
						<c:when test="${con.controlType == 0}">
							<input type="text" name="${con.fieldControl}" value="${vo[con.fieldControl]}" />
						</c:when>
						<c:when test="${con.controlType == 1}">
							<input type="text" name="${con.fieldControl}" value="${vo[con.fieldControl]}" />
						</c:when>
					</c:choose>
				</c:forEach>
				<c:if test="${listControl !=null && listControl.size()>0 }">
					<a class="mtbtn search marginleft" href="#" onclick="submit_onclick()"><i class="mtfa mt-search"></i><span>查询</span></a>
				</c:if>
			</div>
			<div class="checkbox"
				style="position: fixed; top: 45px; margin: 0px; width: 100%; padding-left: 12px; background-color: white; z-index: 5; cursor: pointer;">
				<label> <input id="allcheck" type="checkbox" onchange="checkall();">全选
				</label>
			</div>
			<div>
				<ul id="menuTree" class="ztree" style="margin-top: 70px;"></ul>
			</div>
		</div>
		<input type="hidden" name="resultcallback" id="resultcallback" value="${resultcallback}">
	</form>
</body>
</html>
<script type="text/javascript" src="${ctx}/static/controls/zTree/js/jquery.ztree.core.js"></script>
<script type="text/javascript" src="${ctx}/static/controls/zTree/js/jquery.ztree.excheck.js"></script>

<script type="text/javascript">
	var setting = {

		data : {
			key : {
				name : "result2"
			},
			simpleData : {
				enable : true,
				idKey : "result1",
				pIdKey : "result11"

			}
		},
		check : {
			enable : true,
			chkStyle : "checkbox",
			chkboxType : {
				"Y" : "s",
				"N" : "s"
			}
		},
		callback : {
			beforeClick : beforeClick,
			onCheck : zTreeOnCheck
		}
	};

	var zTree;
	$(document).ready(function() {
		var zNodes = ${data};
		zTree = $.fn.zTree.init($("#menuTree"), setting, zNodes);
		zTree.expandAll(true);
	});

	function beforeClick(treeId, treeNode) {
		zTree.checkNode(treeNode, !treeNode.checked, null, true);
		return false;
	}

	function zTreeOnCheck(event, treeId, treeNode) {

		var allnodes = zTree.getNodes();
		var allnodeCount = allnodes.length;
		for (var i = 0; i < allnodes.length; i++) {
			var node = allnodes[i];
			if (node.children) {
				allnodeCount += node.children.length;
			}
		}

		if (zTree.getCheckedNodes(true).length == allnodeCount) {
			$("#allcheck").prop("checked", "true");
		} else {
			$("#allcheck").removeAttr("checked");
		}
	}

	function select_submit() {
		var treeObj = $.fn.zTree.getZTreeObj("menuTree");
		var nodes = treeObj.getCheckedNodes(true);
		if (nodes.length == 0) {
			layer.msg("请选择数据", {
				icon : 3
			});
		} else {

			var result = [ {
				"result1" : ""
			}, {
				"result2" : ""
			}, {
				"result2" : ""
			}, {
				"result4" : ""
			}, {
				"result5" : ""
			}, {
				"result6" : ""
			}, {
				"result7" : ""
			}, {
				"result8" : ""
			}, {
				"result9" : ""
			}, {
				"result10" : ""
			} ];

			for (var i = 0, l = nodes.length; i < l; i++) {
				if (typeof (result["result1"]) != "undefined") {
					result["result1"] = result["result1"] + "," + nodes[i].result1;
				} else {
					result["result1"] = nodes[i].result1;
				}
				if (typeof (result["result2"]) != "undefined") {
					result["result2"] = result["result2"] + "," + nodes[i].result2;
				} else {
					result["result2"] = nodes[i].result2;
				}

			}

			window.parent.sysSelect_getlay(result, "");
			//执行结果回调函数
			if ($("#resultcallback").val()) {
				eval("window.parent.${resultcallback}(result)");
			}
			//当你在iframe页面关闭自身时
			var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
			parent.layer.close(index); //再执行关闭   
		}
	}

	function checkall() {

		if ($("#allcheck").is(":checked")) {
			zTree.checkAllNodes(true);
		} else {
			zTree.checkAllNodes(false);
		}
	}
</script>
